package run;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * A more refined object representing the interior structure of a cell.
 * @author Thomas Chau
 *
 */
public class Lattice {

	private ArrayList<Bind> bindings = new ArrayList<Bind>();
	private Set<Cell> subcells = new HashSet<Cell>();
	
	private String name; 
	
	public Lattice(String name) {
		this.name = name;
	}

	//	public void addBind(run.client.Bindable lb, BindType bindType, run.client.Bindable rb) {
	public void addBind(run.Bind b) {
			bindings.add(b);
			
			Cell leftOwner = b.getLeft().getOwner();
			Cell rightOwner = b.getRight().getOwner();
	
			subcells.add(leftOwner);
			subcells.add(rightOwner);
	}

	public ArrayList<Bind> getBindings() {
		return bindings;
	}
	
	public String toString() {
		String s = "";
		for (Bind b : bindings) {
			s += b.toString() + "\n";
		}
		return s;
	}
	
	public Set<Cell> getSubcells() {
		return subcells;
	}

	/**
	 * All facets that are destined to receive from the given facet.
	 * @param stimmer
	 * @return
	 */
	public List<Facet> getDestinations(Facet stimmer) {
		List<Facet> dests = new ArrayList<Facet>();
		for (Bind b : bindings) {
			if (b.getLeft() == stimmer)
				dests.add(b.getRight());
		}
		return dests;
	}
	

}
